#!/usr/bin/python
# -*- coding:utf-8 -*-
'''
Created on 2013-6-19

@author: hanjiewu
'''
import MySQLdb
import logging

host = '10.130.134.120'
port = 3347
db = 'db_virus_samples'
user = 'qqsecure'
password = 'szqqsecure2012'
logPath = '/usr/local/app/apache/yunying/mqq_secure/peerswu/exchange_virus_sample_upload/bin/updateviruscount.log'

logging.basicConfig(filename = logPath, filemode = 'a', format = '%(asctime)s - %(levelname)s : %(message)s', level = logging.INFO)

def main():
    conn = MySQLdb.connect(host=host, passwd=password, db=db, port=port, user=user)
    conn.autocommit(True)
    cursor = conn.cursor()
    ret = cursor.execute('insert into virus_samples(virus_id, count) select virus_id, count(*) from db_old_mobile_detect.integrate_analyse where virus_id > 0 group by virus_id on duplicate key update count = values(count)')
    logging.info('affect rows: %d' % ret)
    cursor.close()
    conn.close()

if __name__ == '__main__':
    main()
